package com.example.oasystem.controller.list;


import com.example.oasystem.dao.login.AoaUserDao;
import com.example.oasystem.dao.systemcontrol.SystemcontrolDao;
import com.example.oasystem.entity.list.AoaSysMenu;

import com.example.oasystem.entity.user.AoaUser;
import com.example.oasystem.service.AoaSysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class AoaSysMenuController {
    @Autowired
    AoaUserDao aoaUserDao;
    @Autowired
    AoaSysMenuService aoaSysMenuService;
    @Autowired
    SystemcontrolDao systemcontrolDao;

    @RequestMapping("/index")
    public  String toIndex(HttpServletRequest request, Model model){
        //AoaUser aoaUser = aoaUserDao.selectById(1);
        System.out.println("123123123");
        AoaUser user = (AoaUser)request.getSession().getAttribute("user");
        System.out.println(user);
        Long roleId = user.getRoleId();
        List<AoaSysMenu> aoaSysMenus1 = aoaSysMenuService.selectOneMenuAll(roleId);
        List<AoaSysMenu> aoaSysMenus2 = aoaSysMenuService.selectTwoMenuAll(roleId);


        //通知数量
        Integer notice = systemcontrolDao.getNotice(Math.toIntExact(user.getUserId()));
        model.addAttribute("notice",notice);

        //邮件数量
        Integer mail = systemcontrolDao.getMail(Math.toIntExact(user.getUserId()));
        model.addAttribute("mail",mail);

        //我的任务
        Integer task = systemcontrolDao.getTask(Math.toIntExact(user.getUserId()));
        model.addAttribute("task",task);
        System.out.println("notice:"+notice+" mail:"+mail+" task:"+task);
        model.addAttribute("oneMenuAll",aoaSysMenus1);
        model.addAttribute("twoMenuAll",aoaSysMenus2);
        return "index/index";
    }

    @RequestMapping("/loginout")
    public String loginout(HttpServletRequest request){
        request.getSession().removeAttribute("user");
        return "login/login";
    }
}
